//
//  HEBusinessCardViewController.m
//  HealthFamily
//
//  Created by 吴欧 on 2020/12/11.
//  Copyright © 2020 honglutec. All rights reserved.
//

#import "HEBusinessCardViewController.h"

@interface HEBusinessCardViewController ()

@end

@implementation HEBusinessCardViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"二维码名片";
    self.view.backgroundColor = CViewBgColor;
    
    [self initUI];
}

- (void)initUI {
    
    UserInfo *userInfo = [UserManager sharedUserManager].curUserInfo;
    
    UIView *warp = [UIView new];
    warp.backgroundColor = KWhiteColor;
    [self.view addSubview:warp];
    warp.layer.cornerRadius = 12;

    [warp mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(ZXNavBarHeight + 70);
        make.right.equalTo(self.view).offset(-15);
        make.left.equalTo(self.view).offset(15);
        make.bottom.equalTo(self.view).offset(-70);
    }];
     
    // 头像
    UIImageView *headImgView = [UIImageView new];
    [warp addSubview: headImgView];
    headImgView.layer.cornerRadius = 110 / 2.0;
    headImgView.layer.masksToBounds = YES;
    [headImgView sd_setImageWithURL:[NSURL URLWithString:userInfo.avatar] placeholderImage:IMAGE_NAMED(@"defualt_icon")];
    headImgView.contentMode = UIViewContentModeScaleAspectFill;

    [headImgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(warp).offset(-50);
        make.centerX.equalTo(warp);
        make.width.height.offset(110);
    }];
    
    // 姓名
    QMUIButton *nameBtn = [[QMUIButton alloc] init];
    nameBtn.imagePosition = QMUIButtonImagePositionRight;// 将图片位置改为在文字下方
    nameBtn.tintColorAdjustsTitleAndImage = CNavLightBlackColor;
    nameBtn.adjustsImageTintColorAutomatically = NO;
    nameBtn.spacingBetweenImageAndTitle = 10;
    [nameBtn setImage:IMAGE_NAMED(@"man") forState:UIControlStateNormal];
    [nameBtn setTitle: [DYTools isBlankString: userInfo.realname] ? userInfo.username : userInfo.realname forState:UIControlStateNormal];
    nameBtn.titleLabel.font = DYBlodFont(16);
    [warp addSubview:nameBtn];
  
    [nameBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(headImgView.mas_bottom).offset(20);
        make.centerX.equalTo(warp);
    }];
    
    // 二维码
    UIImageView *codeWarpView = [UIImageView new];
    codeWarpView.image = IMAGE_NAMED(@"scan_bg");
    [warp addSubview: codeWarpView];
    
    [codeWarpView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(nameBtn.mas_bottom).offset(20);
        make.centerX.equalTo(warp);
        make.width.height.offset(206);
    }];
 
    // 二维码
    UIImageView *qcodeView = [UIImageView new];
    [qcodeView sd_setImageWithURL:[NSURL URLWithString:userInfo.qrcode_url]];
    [codeWarpView addSubview: qcodeView];
    qcodeView.contentMode = UIViewContentModeScaleAspectFill;

    [qcodeView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(codeWarpView).offset(15);
        make.left.equalTo(codeWarpView).offset(15);
        make.right.equalTo(codeWarpView).offset(-15);
        make.bottom.equalTo(codeWarpView).offset(-15);
    }];
    
    
    // 条形码
    UIImageView *qbarView = [UIImageView new];
    [qbarView sd_setImageWithURL:[NSURL URLWithString:userInfo.bar_code_url]];
    qbarView.contentMode = UIViewContentModeScaleAspectFill; 
    [warp addSubview: qbarView];
    
    [qbarView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(codeWarpView.mas_bottom).offset(20);
        make.centerX.equalTo(warp);
        make.width.offset(280);
        make.height.offset(90);
    }];
    
}

@end
